package com.qijia.travel.domain.example;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.qijia.travel.common.Constants;
import com.qijia.travel.helper.DateHelper;
import com.qijia.travel.vo.StatisticsVo;

public class StatisticsExample extends BaseExample {
	protected String orderByClause;
	protected String havingClause;
	protected List<Criteria> oredCriteria;

	public StatisticsExample() {
		oredCriteria = new ArrayList<Criteria>();
	}

	protected StatisticsExample(StatisticsExample example) {
		this.orderByClause = example.orderByClause;
		this.oredCriteria = example.oredCriteria;
	}

	public void setOrderByClause(String orderByClause) {
		this.orderByClause = orderByClause;
	}

	public String getOrderByClause() {
		return orderByClause;
	}

	public String getHavingClause() {
		return havingClause;
	}

	public void setHavingClause(String havingClause) {
		this.havingClause = havingClause;
	}

	public List<Criteria> getOredCriteria() {
		return oredCriteria;
	}

	public void or(Criteria criteria) {
		oredCriteria.add(criteria);
	}

	public Criteria createCriteria(StatisticsVo vo) {
		Criteria criteria = createCriteriaInternal(vo);
		if (oredCriteria.size() == 0) {
			oredCriteria.add(criteria);
		}
		return criteria;
	}

	protected Criteria createCriteriaInternal(StatisticsVo vo) {
		Criteria criteria = new Criteria(vo);
		return criteria;
	}

	public void clear() {
		oredCriteria.clear();
	}

	public static class Criteria {
		protected List<String> criteriaWithoutValue;
		protected List<Map<String, Object>> criteriaWithSingleValue;
		protected List<Map<String, Object>> criteriaWithListValue;
		protected List<Map<String, Object>> criteriaWithBetweenValue;

		protected Criteria(StatisticsVo vo) {
			super();
			criteriaWithoutValue = new ArrayList<String>();
			criteriaWithSingleValue = new ArrayList<Map<String, Object>>();
			criteriaWithListValue = new ArrayList<Map<String, Object>>();
			criteriaWithBetweenValue = new ArrayList<Map<String, Object>>();

			if (vo != null) {
				if (vo.getSearchCode() != null && vo.getSearchKeyword() != null
						&& vo.getSearchKeyword().length() > 0) {
					switch (vo.getSearchCode()) {
					case Constants.SEARCH_GUIDE_NAME_CODE: {
						this
								.andGuideNameLike("%" + vo.getSearchKeyword()
										+ "%");
					}
						;
						break;
					case Constants.SEARCH_GUIDE_ID_CODE: {
						try {
							this.andGuideIdEqualTo(Integer.parseInt(vo
									.getSearchKeyword()));
						} catch (NumberFormatException e) {

						}
					}
						;
						break;
					case Constants.SEARCH_GUIDE_TYPE_CODE: {
						try {
							this.andGuideTypeEqualTo(Integer.parseInt(vo
									.getSearchKeyword()));
						} catch (NumberFormatException e) {

						}
					}
						;
						break;
					default:
						break;
					}
				}

				if (vo.getDateCode() != null
						&& (vo.getStDate() != null && vo.getStDate().length() > 0)) {
					Calendar startDate = Calendar.getInstance();
					Calendar endDate = Calendar.getInstance();

					try {
						startDate.setTime(DateHelper.parseToDate(
								vo.getStDate(), DateHelper.yyyyMMdd));
						if (vo.getEdDate() != null
								&& vo.getEdDate().length() > 0) {
							endDate.setTime(DateHelper.parseToDate(vo
									.getEdDate(), DateHelper.yyyyMMdd));
						}

						switch (vo.getDateCode()) {
						case Constants.DATETYPE_GROUP_START_DATE_CODE: {
							this.andTgdStartDtGreaterThanOrEqualTo(startDate
									.getTime());
							this.andTgdStartDtLessThanOrEqualTo(endDate
									.getTime());
						}
							;
							break;
						case Constants.DATETYPE_GROUP_END_DATE_CODE: {
							this.andTgdEndDtGreaterThanOrEqualTo(startDate
									.getTime());
							this
									.andTgdEndDtLessThanOrEqualTo(endDate
											.getTime());
						}
							break;
						default:
							break;
						}
					} catch (Exception e) {
						e.printStackTrace();
					}

				}
			}
		}

		public boolean isValid() {
			return criteriaWithoutValue.size() > 0
					|| criteriaWithSingleValue.size() > 0
					|| criteriaWithListValue.size() > 0
					|| criteriaWithBetweenValue.size() > 0;
		}

		public List<String> getCriteriaWithoutValue() {
			return criteriaWithoutValue;
		}

		public List<Map<String, Object>> getCriteriaWithSingleValue() {
			return criteriaWithSingleValue;
		}

		public List<Map<String, Object>> getCriteriaWithListValue() {
			return criteriaWithListValue;
		}

		public List<Map<String, Object>> getCriteriaWithBetweenValue() {
			return criteriaWithBetweenValue;
		}

		protected void addCriterion(String condition) {
			if (condition == null) {
				throw new RuntimeException("Value for condition cannot be null");
			}
			criteriaWithoutValue.add(condition);
		}

		protected void addCriterion(String condition, Object value,
				String property) {
			if (value == null) {
				throw new RuntimeException("Value for " + property
						+ " cannot be null");
			}
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("condition", condition);
			map.put("value", value);
			criteriaWithSingleValue.add(map);
		}

		protected void addCriterion(String condition,
				List<? extends Object> values, String property) {
			if (values == null || values.size() == 0) {
				throw new RuntimeException("Value list for " + property
						+ " cannot be null or empty");
			}
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("condition", condition);
			map.put("values", values);
			criteriaWithListValue.add(map);
		}

		protected void addCriterion(String condition, Object value1,
				Object value2, String property) {
			if (value1 == null || value2 == null) {
				throw new RuntimeException("Between values for " + property
						+ " cannot be null");
			}
			List<Object> list = new ArrayList<Object>();
			list.add(value1);
			list.add(value2);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("condition", condition);
			map.put("values", list);
			criteriaWithBetweenValue.add(map);
		}

		public Criteria andGuideIdIsNull() {
			addCriterion("guide_id is null");
			return this;
		}

		public Criteria andGuideIdIsNotNull() {
			addCriterion("guide_id is not null");
			return this;
		}

		public Criteria andGuideIdEqualTo(Integer value) {
			addCriterion("guide_id =", value, "guideId");
			return this;
		}

		public Criteria andGuideIdNotEqualTo(Integer value) {
			addCriterion("guide_id <>", value, "guideId");
			return this;
		}

		public Criteria andGuideIdGreaterThan(Integer value) {
			addCriterion("guide_id >", value, "guideId");
			return this;
		}

		public Criteria andGuideIdGreaterThanOrEqualTo(Integer value) {
			addCriterion("guide_id >=", value, "guideId");
			return this;
		}

		public Criteria andGuideIdLessThan(Integer value) {
			addCriterion("guide_id <", value, "guideId");
			return this;
		}

		public Criteria andGuideIdLessThanOrEqualTo(Integer value) {
			addCriterion("guide_id <=", value, "guideId");
			return this;
		}

		public Criteria andGuideIdIn(List<Integer> values) {
			addCriterion("guide_id in", values, "guideId");
			return this;
		}

		public Criteria andGuideIdNotIn(List<Integer> values) {
			addCriterion("guide_id not in", values, "guideId");
			return this;
		}

		public Criteria andGuideIdBetween(Integer value1, Integer value2) {
			addCriterion("guide_id between", value1, value2, "guideId");
			return this;
		}

		public Criteria andGuideIdNotBetween(Integer value1, Integer value2) {
			addCriterion("guide_id not between", value1, value2, "guideId");
			return this;
		}

		public Criteria andGuideNameIsNull() {
			addCriterion("guide_name is null");
			return this;
		}

		public Criteria andGuideNameIsNotNull() {
			addCriterion("guide_name is not null");
			return this;
		}

		public Criteria andGuideNameEqualTo(String value) {
			addCriterion("guide_name =", value, "guideName");
			return this;
		}

		public Criteria andGuideNameNotEqualTo(String value) {
			addCriterion("guide_name <>", value, "guideName");
			return this;
		}

		public Criteria andGuideNameGreaterThan(String value) {
			addCriterion("guide_name >", value, "guideName");
			return this;
		}

		public Criteria andGuideNameGreaterThanOrEqualTo(String value) {
			addCriterion("guide_name >=", value, "guideName");
			return this;
		}

		public Criteria andGuideNameLessThan(String value) {
			addCriterion("guide_name <", value, "guideName");
			return this;
		}

		public Criteria andGuideNameLessThanOrEqualTo(String value) {
			addCriterion("guide_name <=", value, "guideName");
			return this;
		}

		public Criteria andGuideNameLike(String value) {
			addCriterion("guide_name like", value, "guideName");
			return this;
		}

		public Criteria andGuideNameNotLike(String value) {
			addCriterion("guide_name not like", value, "guideName");
			return this;
		}

		public Criteria andGuideNameIn(List<String> values) {
			addCriterion("guide_name in", values, "guideName");
			return this;
		}

		public Criteria andGuideNameNotIn(List<String> values) {
			addCriterion("guide_name not in", values, "guideName");
			return this;
		}

		public Criteria andGuideNameBetween(String value1, String value2) {
			addCriterion("guide_name between", value1, value2, "guideName");
			return this;
		}

		public Criteria andGuideNameNotBetween(String value1, String value2) {
			addCriterion("guide_name not between", value1, value2, "guideName");
			return this;
		}

		public Criteria andTgdStartDtIsNull() {
			addCriterion("tgd_start_dt is null");
			return this;
		}

		public Criteria andTgdStartDtIsNotNull() {
			addCriterion("tgd_start_dt is not null");
			return this;
		}

		public Criteria andTgdStartDtEqualTo(Date value) {
			addCriterion("tgd_start_dt =", value, "tgdStartDt");
			return this;
		}

		public Criteria andTgdStartDtNotEqualTo(Date value) {
			addCriterion("tgd_start_dt <>", value, "tgdStartDt");
			return this;
		}

		public Criteria andTgdStartDtGreaterThan(Date value) {
			addCriterion("tgd_start_dt >", value, "tgdStartDt");
			return this;
		}

		public Criteria andTgdStartDtGreaterThanOrEqualTo(Date value) {
			addCriterion("tgd_start_dt >=", value, "tgdStartDt");
			return this;
		}

		public Criteria andTgdStartDtLessThan(Date value) {
			addCriterion("tgd_start_dt <", value, "tgdStartDt");
			return this;
		}

		public Criteria andTgdStartDtLessThanOrEqualTo(Date value) {
			addCriterion("tgd_start_dt <=", value, "tgdStartDt");
			return this;
		}

		public Criteria andTgdStartDtIn(List<Date> values) {
			addCriterion("tgd_start_dt in", values, "tgdStartDt");
			return this;
		}

		public Criteria andTgdStartDtNotIn(List<Date> values) {
			addCriterion("tgd_start_dt not in", values, "tgdStartDt");
			return this;
		}

		public Criteria andTgdStartDtBetween(Date value1, Date value2) {
			addCriterion("tgd_start_dt between", value1, value2, "tgdStartDt");
			return this;
		}

		public Criteria andTgdStartDtNotBetween(Date value1, Date value2) {
			addCriterion("tgd_start_dt not between", value1, value2,
					"tgdStartDt");
			return this;
		}

		public Criteria andTgdEndDtIsNull() {
			addCriterion("tgd_end_dt is null");
			return this;
		}

		public Criteria andTgdEndDtIsNotNull() {
			addCriterion("tgd_end_dt is not null");
			return this;
		}

		public Criteria andTgdEndDtEqualTo(Date value) {
			addCriterion("tgd_end_dt =", value, "tgdEndDt");
			return this;
		}

		public Criteria andTgdEndDtNotEqualTo(Date value) {
			addCriterion("tgd_end_dt <>", value, "tgdEndDt");
			return this;
		}

		public Criteria andTgdEndDtGreaterThan(Date value) {
			addCriterion("tgd_end_dt >", value, "tgdEndDt");
			return this;
		}

		public Criteria andTgdEndDtGreaterThanOrEqualTo(Date value) {
			addCriterion("tgd_end_dt >=", value, "tgdEndDt");
			return this;
		}

		public Criteria andTgdEndDtLessThan(Date value) {
			addCriterion("tgd_end_dt <", value, "tgdEndDt");
			return this;
		}

		public Criteria andTgdEndDtLessThanOrEqualTo(Date value) {
			addCriterion("tgd_end_dt <=", value, "tgdEndDt");
			return this;
		}

		public Criteria andTgdEndDtIn(List<Date> values) {
			addCriterion("tgd_end_dt in", values, "tgdEndDt");
			return this;
		}

		public Criteria andTgdEndDtNotIn(List<Date> values) {
			addCriterion("tgd_end_dt not in", values, "tgdEndDt");
			return this;
		}

		public Criteria andTgdEndDtBetween(Date value1, Date value2) {
			addCriterion("tgd_end_dt between", value1, value2, "tgdEndDt");
			return this;
		}

		public Criteria andTgdEndDtNotBetween(Date value1, Date value2) {
			addCriterion("tgd_end_dt not between", value1, value2, "tgdEndDt");
			return this;
		}
		
		public Criteria andGuideTypeEqualTo(Integer value) {
			addCriterion("guide_type =", value, "guideType");
			return this;
		}

	}

}
